package com.yihu.cms.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yihu.beans.Poster;
import com.yihu.beans.PosterQuery;
import com.yihu.cms.service.PosterService;

@Controller
public class PosterController extends BaseController{
	private final Logger logger = LoggerFactory.getLogger(PosterController.class); 
	PosterService service = new PosterService();
	
	@RequestMapping(value = "/poster", method = RequestMethod.POST)
	public @ResponseBody Object add(@RequestBody Poster poster) {
		return service.addPoster(poster);
	}
	
	@RequestMapping(value = "/poster/{id}", method = RequestMethod.PUT)
	public @ResponseBody Object updatePoster(@RequestBody Poster poster,@PathVariable("id") String id) {
		poster.setId(id);
		return service.updatePoster(poster);
	}
	
	@RequestMapping(value = "/poster/{id}", method = RequestMethod.DELETE)
	public @ResponseBody Object delete(@PathVariable("id") String id) {
	
		return service.delPoster(id);
	}
	
	@RequestMapping(value = "/poster/list" , method = RequestMethod.GET)
	// , method = RequestMethod.PATCH
	public @ResponseBody Object getPosters(PosterQuery query) {
		logger.debug("getPosters: "+query);
		return service.getPosters(query);
	}
	
	@RequestMapping(value = "/poster/{id}", method = RequestMethod.GET)
	public @ResponseBody Object findPoster(@PathVariable("id") String id) {
		Poster p = new Poster();
		p.setId(id);
		return service.findPoster(p);
	}
	
}
